package everyday.luogu;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/26/17:26
 * @Description:
 */
public class Num33 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int[] arr=new int[a];
        while(scanner.hasNextLine()){
            for (int i = 0; i < a; i++) {
                arr[i]=scanner.nextInt();
            }
            Arrays.sort(arr);
            if(b==0){
                System.out.println(arr[a-1]-arr[0]);
            }
        }
    }
}
